package models.cms;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

import models.sys.User;
import play.db.jpa.Model;

/**
 * 资源
 */
@Entity(name = "t_resource")
public class Resource extends Model {

    public static enum ResourceType {
        IMAGE, OTHER;

        public static ResourceType detect(String type) {
            switch (type) {
                case "image/jpeg":
                case "image/png":
                    return IMAGE;
                default:
                    return OTHER;
            }
        }
    }

    public String name;
    public String hash;
    public String path;
    public String content_type;
    public ResourceType type;
    @ManyToOne
    public User user;
    public Date created_at;
    public long size;

}
